﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SMA.GENTEv1.Dados;

namespace SMA.GENTEv1
{
    public class GrauInstrucao
    {
        #region Variaveis Membro
        private int _idGrauInstrucao;
        private string _descricao;
        private GENTEEntities _context;
        #endregion

        #region Parametros
        public int IdGrauInstrucao
        {
            get { return _idGrauInstrucao; }
            set { _idGrauInstrucao = value; }
        }
        public string Descricao
        {
            get { return _descricao; }
            set { _descricao = value; }
        }
        #endregion

        #region Construtores
        public GrauInstrucao()
        {
            try
            {
                _context = new GENTEEntities();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public GrauInstrucao(int idGrauInstrucao)
        {
            try
            {
                _context = new GENTEEntities();
                Carregar(idGrauInstrucao);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Privados
        private void Carregar(int idGrauInstrucao)
        {
            try
            {
                var consulta = from gi in _context.tab_grau_instrucao
                               where gi.Id_grauinstrucao == idGrauInstrucao
                               select gi;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    this.IdGrauInstrucao = list.Id_grauinstrucao;
                    this.Descricao = list.descricao;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos Publicos

        #region Metodos de Selecao
        public List<GrauInstrucao> SelectAll()
        {
            try
            {
                List<GrauInstrucao> listGrauInstrucao = new List<GrauInstrucao>();

                var consulta = from gi in _context.tab_grau_instrucao
                               select gi;

                var listConsulta = consulta.ToList();

                foreach (var list in listConsulta)
                {
                    GrauInstrucao grauInstrucao = new GrauInstrucao();
                    grauInstrucao.IdGrauInstrucao = list.Id_grauinstrucao;
                    grauInstrucao.Descricao = list.descricao;

                    listGrauInstrucao.Add(grauInstrucao);
                }

                return listGrauInstrucao;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        #endregion

        #region Metodos de Persistencia
        #endregion

        #endregion
    }
}
